import 'package:flutter_deer/generated/json/base/json_convert_content.dart';
import 'package:flutter_deer/database/beans/discount/discount_resp_entity.dart';
import 'package:flutter_deer/database/beans/pay/create_order_entity.dart';

import 'package:flutter_deer/util/input_formatter/money_util.dart';


DiscountItem $DiscountItemFromJson(Map<String, dynamic> json) {
  final DiscountItem discountItem = DiscountItem();
  final bool? available = jsonConvert.convert<bool>(json['available']);
  if (available != null) {
    discountItem.available = available;
  }
  final bool? canCompositePay = jsonConvert.convert<bool>(json['canCompositePay']);
  if (canCompositePay != null) {
    discountItem.canCompositePay = canCompositePay;
  }
  final bool? canUseStoreCoupon = jsonConvert.convert<bool>(json['canUseStoreCoupon']);
  if (canUseStoreCoupon != null) {
    discountItem.canUseStoreCoupon = canUseStoreCoupon;
  }
  final String? cardNo = jsonConvert.convert<String>(json['cardNo']);
  if (cardNo != null) {
    discountItem.cardNo = cardNo;
  }
  final int? couponCount = jsonConvert.convert<int>(json['couponCount']);
  if (couponCount != null) {
    discountItem.couponCount = couponCount;
  }
  final String? couponDiscountAmount = jsonConvert.convert<String>(json['couponDiscountAmount']);
  if (couponDiscountAmount != null) {
    discountItem.couponDiscountAmount = couponDiscountAmount;
  }
  final String? couponId = jsonConvert.convert<String>(json['couponId']);
  if (couponId != null) {
    discountItem.couponId = couponId;
  }
  final List<CouponList>? couponList = (json['couponList'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<CouponList>(e) as CouponList).toList();
  if (couponList != null) {
    discountItem.couponList = couponList;
  }
  final String? couponName = jsonConvert.convert<String>(json['couponName']);
  if (couponName != null) {
    discountItem.couponName = couponName;
  }
  final String? couponNotUseDesc = jsonConvert.convert<String>(json['couponNotUseDesc']);
  if (couponNotUseDesc != null) {
    discountItem.couponNotUseDesc = couponNotUseDesc;
  }
  final int? couponSelectType = jsonConvert.convert<int>(json['couponSelectType']);
  if (couponSelectType != null) {
    discountItem.couponSelectType = couponSelectType;
  }
  final String? discountAmount = jsonConvert.convert<String>(json['discountAmount']);
  if (discountAmount != null) {
    discountItem.discountAmount = discountAmount;
  }
  final List<Discount>? discounts = (json['discounts'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<Discount>(e) as Discount).toList();
  if (discounts != null) {
    discountItem.discounts = discounts;
  }
  final bool? enableBuyExcludeOil = jsonConvert.convert<bool>(json['enableBuyExcludeOil']);
  if (enableBuyExcludeOil != null) {
    discountItem.enableBuyExcludeOil = enableBuyExcludeOil;
  }
  final String? energyDiscountAmount = jsonConvert.convert<String>(json['energyDiscountAmount']);
  if (energyDiscountAmount != null) {
    discountItem.energyDiscountAmount = energyDiscountAmount;
  }
  final IntegralToCashDiscount? integralToCashDiscount = jsonConvert.convert<IntegralToCashDiscount>(json['integralToCashDiscount']);
  if (integralToCashDiscount != null) {
    discountItem.integralToCashDiscount = integralToCashDiscount;
  }
  final bool? maxDiscount = jsonConvert.convert<bool>(json['maxDiscount']);
  if (maxDiscount != null) {
    discountItem.maxDiscount = maxDiscount;
  }
  final String? storeDiscountAmount = jsonConvert.convert<String>(json['storeDiscountAmount']);
  if (storeDiscountAmount != null) {
    discountItem.storeDiscountAmount = storeDiscountAmount;
  }
  final List<StoreGoodsInfos>? storeGoodsInfos = (json['storeGoodsInfos'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<StoreGoodsInfos>(e) as StoreGoodsInfos).toList();
  if (storeGoodsInfos != null) {
    discountItem.storeGoodsInfos = storeGoodsInfos;
  }
  final String? memberAccountAmount = jsonConvert.convert<String>(json['memberAccountAmount']);
  if (memberAccountAmount != null) {
    discountItem.memberAccountAmount = memberAccountAmount;
  }
  final String? memberAccountId = jsonConvert.convert<String>(json['memberAccountId']);
  if (memberAccountId != null) {
    discountItem.memberAccountId = memberAccountId;
  }
  final String? memberAccountType = jsonConvert.convert<String>(json['memberAccountType']);
  if (memberAccountType != null) {
    discountItem.memberAccountType = memberAccountType;
  }
  final String? belongMchType = jsonConvert.convert<String>(json['belongMchType']);
  if (belongMchType != null) {
    discountItem.belongMchType = belongMchType;
  }
  final String? entityType = jsonConvert.convert<String>(json['entityType']);
  if (entityType != null) {
    discountItem.entityType = entityType;
  }
  final String? payTypeId = jsonConvert.convert<String>(json['payTypeId']);
  if (payTypeId != null) {
    discountItem.payTypeId = payTypeId;
  }
  final String? payTypeName = jsonConvert.convert<String>(json['payTypeName']);
  if (payTypeName != null) {
    discountItem.payTypeName = payTypeName;
  }
  final String? showCardNo = jsonConvert.convert<String>(json['showCardNo']);
  if (showCardNo != null) {
    discountItem.showCardNo = showCardNo;
  }
  final String? templateRechargeStatus = jsonConvert.convert<String>(json['templateRechargeStatus']);
  if (templateRechargeStatus != null) {
    discountItem.templateRechargeStatus = templateRechargeStatus;
  }
  final String? payAmount = jsonConvert.convert<String>(json['payAmount']);
  if (payAmount != null) {
    discountItem.payAmount = payAmount;
  }
  final String? payableAmount = jsonConvert.convert<String>(json['payableAmount']);
  if (payableAmount != null) {
    discountItem.payableAmount = payableAmount;
  }
  final String? unavailableCode = jsonConvert.convert<String>(json['unavailableCode']);
  if (unavailableCode != null) {
    discountItem.unavailableCode = unavailableCode;
  }
  final String? unavailableMsg = jsonConvert.convert<String>(json['unavailableMsg']);
  if (unavailableMsg != null) {
    discountItem.unavailableMsg = unavailableMsg;
  }
  final int? isSubRecharge = jsonConvert.convert<int>(json['isSubRecharge']);
  if (isSubRecharge != null) {
    discountItem.isSubRecharge = isSubRecharge;
  }
  return discountItem;
}

Map<String, dynamic> $DiscountItemToJson(DiscountItem entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['available'] = entity.available;
  data['canCompositePay'] = entity.canCompositePay;
  data['canUseStoreCoupon'] = entity.canUseStoreCoupon;
  data['cardNo'] = entity.cardNo;
  data['couponCount'] = entity.couponCount;
  data['couponDiscountAmount'] = entity.couponDiscountAmount;
  data['couponId'] = entity.couponId;
  data['couponList'] = entity.couponList.map((v) => v.toJson()).toList();
  data['couponName'] = entity.couponName;
  data['couponNotUseDesc'] = entity.couponNotUseDesc;
  data['couponSelectType'] = entity.couponSelectType;
  data['discountAmount'] = entity.discountAmount;
  data['discounts'] = entity.discounts.map((v) => v.toJson()).toList();
  data['enableBuyExcludeOil'] = entity.enableBuyExcludeOil;
  data['energyDiscountAmount'] = entity.energyDiscountAmount;
  data['integralToCashDiscount'] = entity.integralToCashDiscount?.toJson();
  data['maxDiscount'] = entity.maxDiscount;
  data['storeDiscountAmount'] = entity.storeDiscountAmount;
  data['storeGoodsInfos'] = entity.storeGoodsInfos.map((v) => v.toJson()).toList();
  data['memberAccountAmount'] = entity.memberAccountAmount;
  data['memberAccountId'] = entity.memberAccountId;
  data['memberAccountType'] = entity.memberAccountType;
  data['belongMchType'] = entity.belongMchType;
  data['entityType'] = entity.entityType;
  data['payTypeId'] = entity.payTypeId;
  data['payTypeName'] = entity.payTypeName;
  data['showCardNo'] = entity.showCardNo;
  data['templateRechargeStatus'] = entity.templateRechargeStatus;
  data['payAmount'] = entity.payAmount;
  data['payableAmount'] = entity.payableAmount;
  data['unavailableCode'] = entity.unavailableCode;
  data['unavailableMsg'] = entity.unavailableMsg;
  data['isSubRecharge'] = entity.isSubRecharge;
  return data;
}

extension DiscountItemExtension on DiscountItem {
  DiscountItem copyWith({
    bool? available,
    bool? canCompositePay,
    bool? canUseStoreCoupon,
    String? cardNo,
    int? couponCount,
    String? couponDiscountAmount,
    String? couponId,
    List<CouponList>? couponList,
    String? couponName,
    String? couponNotUseDesc,
    int? couponSelectType,
    String? discountAmount,
    List<Discount>? discounts,
    bool? enableBuyExcludeOil,
    String? energyDiscountAmount,
    IntegralToCashDiscount? integralToCashDiscount,
    bool? maxDiscount,
    String? storeDiscountAmount,
    List<StoreGoodsInfos>? storeGoodsInfos,
    String? memberAccountAmount,
    String? memberAccountId,
    String? memberAccountType,
    String? belongMchType,
    String? entityType,
    String? payTypeId,
    String? payTypeName,
    String? showCardNo,
    String? templateRechargeStatus,
    String? payAmount,
    String? payableAmount,
    String? unavailableCode,
    String? unavailableMsg,
    int? isSubRecharge,
  }) {
    return DiscountItem()
      ..available = available ?? this.available
      ..canCompositePay = canCompositePay ?? this.canCompositePay
      ..canUseStoreCoupon = canUseStoreCoupon ?? this.canUseStoreCoupon
      ..cardNo = cardNo ?? this.cardNo
      ..couponCount = couponCount ?? this.couponCount
      ..couponDiscountAmount = couponDiscountAmount ?? this.couponDiscountAmount
      ..couponId = couponId ?? this.couponId
      ..couponList = couponList ?? this.couponList
      ..couponName = couponName ?? this.couponName
      ..couponNotUseDesc = couponNotUseDesc ?? this.couponNotUseDesc
      ..couponSelectType = couponSelectType ?? this.couponSelectType
      ..discountAmount = discountAmount ?? this.discountAmount
      ..discounts = discounts ?? this.discounts
      ..enableBuyExcludeOil = enableBuyExcludeOil ?? this.enableBuyExcludeOil
      ..energyDiscountAmount = energyDiscountAmount ?? this.energyDiscountAmount
      ..integralToCashDiscount = integralToCashDiscount ?? this.integralToCashDiscount
      ..maxDiscount = maxDiscount ?? this.maxDiscount
      ..storeDiscountAmount = storeDiscountAmount ?? this.storeDiscountAmount
      ..storeGoodsInfos = storeGoodsInfos ?? this.storeGoodsInfos
      ..memberAccountAmount = memberAccountAmount ?? this.memberAccountAmount
      ..memberAccountId = memberAccountId ?? this.memberAccountId
      ..memberAccountType = memberAccountType ?? this.memberAccountType
      ..belongMchType = belongMchType ?? this.belongMchType
      ..entityType = entityType ?? this.entityType
      ..payTypeId = payTypeId ?? this.payTypeId
      ..payTypeName = payTypeName ?? this.payTypeName
      ..showCardNo = showCardNo ?? this.showCardNo
      ..templateRechargeStatus = templateRechargeStatus ?? this.templateRechargeStatus
      ..payAmount = payAmount ?? this.payAmount
      ..payableAmount = payableAmount ?? this.payableAmount
      ..unavailableCode = unavailableCode ?? this.unavailableCode
      ..unavailableMsg = unavailableMsg ?? this.unavailableMsg
      ..isSubRecharge = isSubRecharge ?? this.isSubRecharge;
  }
}

CouponList $CouponListFromJson(Map<String, dynamic> json) {
  final CouponList couponList = CouponList();
  final String? couponAmount = jsonConvert.convert<String>(json['couponAmount']);
  if (couponAmount != null) {
    couponList.couponAmount = couponAmount;
  }
  final String? couponId = jsonConvert.convert<String>(json['couponId']);
  if (couponId != null) {
    couponList.couponId = couponId;
  }
  final String? couponName = jsonConvert.convert<String>(json['couponName']);
  if (couponName != null) {
    couponList.couponName = couponName;
  }
  final String? couponType = jsonConvert.convert<String>(json['couponType']);
  if (couponType != null) {
    couponList.couponType = couponType;
  }
  final List<CouponGoodsDetails>? goodsDetails = (json['goodsDetails'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<CouponGoodsDetails>(e) as CouponGoodsDetails).toList();
  if (goodsDetails != null) {
    couponList.goodsDetails = goodsDetails;
  }
  return couponList;
}

Map<String, dynamic> $CouponListToJson(CouponList entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['couponAmount'] = entity.couponAmount;
  data['couponId'] = entity.couponId;
  data['couponName'] = entity.couponName;
  data['couponType'] = entity.couponType;
  data['goodsDetails'] = entity.goodsDetails?.map((v) => v.toJson()).toList();
  return data;
}

extension CouponListExtension on CouponList {
  CouponList copyWith({
    String? couponAmount,
    String? couponId,
    String? couponName,
    String? couponType,
    List<CouponGoodsDetails>? goodsDetails,
  }) {
    return CouponList()
      ..couponAmount = couponAmount ?? this.couponAmount
      ..couponId = couponId ?? this.couponId
      ..couponName = couponName ?? this.couponName
      ..couponType = couponType ?? this.couponType
      ..goodsDetails = goodsDetails ?? this.goodsDetails;
  }
}

CouponGoodsDetails $CouponGoodsDetailsFromJson(Map<String, dynamic> json) {
  final CouponGoodsDetails couponGoodsDetails = CouponGoodsDetails();
  final String? discountAmount = jsonConvert.convert<String>(json['discountAmount']);
  if (discountAmount != null) {
    couponGoodsDetails.discountAmount = discountAmount;
  }
  final String? discountQuantity = jsonConvert.convert<String>(json['discountQuantity']);
  if (discountQuantity != null) {
    couponGoodsDetails.discountQuantity = discountQuantity;
  }
  final String? goodsId = jsonConvert.convert<String>(json['goodsId']);
  if (goodsId != null) {
    couponGoodsDetails.goodsId = goodsId;
  }
  final String? salesChannelGoodsId = jsonConvert.convert<String>(json['salesChannelGoodsId']);
  if (salesChannelGoodsId != null) {
    couponGoodsDetails.salesChannelGoodsId = salesChannelGoodsId;
  }
  final String? useIntegral = jsonConvert.convert<String>(json['useIntegral']);
  if (useIntegral != null) {
    couponGoodsDetails.useIntegral = useIntegral;
  }
  return couponGoodsDetails;
}

Map<String, dynamic> $CouponGoodsDetailsToJson(CouponGoodsDetails entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['discountAmount'] = entity.discountAmount;
  data['discountQuantity'] = entity.discountQuantity;
  data['goodsId'] = entity.goodsId;
  data['salesChannelGoodsId'] = entity.salesChannelGoodsId;
  data['useIntegral'] = entity.useIntegral;
  return data;
}

extension CouponGoodsDetailsExtension on CouponGoodsDetails {
  CouponGoodsDetails copyWith({
    String? discountAmount,
    String? discountQuantity,
    String? goodsId,
    String? salesChannelGoodsId,
    String? useIntegral,
  }) {
    return CouponGoodsDetails()
      ..discountAmount = discountAmount ?? this.discountAmount
      ..discountQuantity = discountQuantity ?? this.discountQuantity
      ..goodsId = goodsId ?? this.goodsId
      ..salesChannelGoodsId = salesChannelGoodsId ?? this.salesChannelGoodsId
      ..useIntegral = useIntegral ?? this.useIntegral;
  }
}

IntegralToCashDiscount $IntegralToCashDiscountFromJson(Map<String, dynamic> json) {
  final IntegralToCashDiscount integralToCashDiscount = IntegralToCashDiscount();
  final bool? available = jsonConvert.convert<bool>(json['available']);
  if (available != null) {
    integralToCashDiscount.available = available;
  }
  final String? cashValue = jsonConvert.convert<String>(json['cashValue']);
  if (cashValue != null) {
    integralToCashDiscount.cashValue = cashValue;
  }
  final String? discountAmount = jsonConvert.convert<String>(json['discountAmount']);
  if (discountAmount != null) {
    integralToCashDiscount.discountAmount = discountAmount;
  }
  final String? integralValue = jsonConvert.convert<String>(json['integralValue']);
  if (integralValue != null) {
    integralToCashDiscount.integralValue = integralValue;
  }
  final String? maxUseIntegral = jsonConvert.convert<String>(json['maxUseIntegral']);
  if (maxUseIntegral != null) {
    integralToCashDiscount.maxUseIntegral = maxUseIntegral;
  }
  final String? memberIntegral = jsonConvert.convert<String>(json['memberIntegral']);
  if (memberIntegral != null) {
    integralToCashDiscount.memberIntegral = memberIntegral;
  }
  final String? promotionsCode = jsonConvert.convert<String>(json['promotionsCode']);
  if (promotionsCode != null) {
    integralToCashDiscount.promotionsCode = promotionsCode;
  }
  final String? promotionsId = jsonConvert.convert<String>(json['promotionsId']);
  if (promotionsId != null) {
    integralToCashDiscount.promotionsId = promotionsId;
  }
  final String? reason = jsonConvert.convert<String>(json['reason']);
  if (reason != null) {
    integralToCashDiscount.reason = reason;
  }
  final String? type = jsonConvert.convert<String>(json['type']);
  if (type != null) {
    integralToCashDiscount.type = type;
  }
  final String? typeDesc = jsonConvert.convert<String>(json['typeDesc']);
  if (typeDesc != null) {
    integralToCashDiscount.typeDesc = typeDesc;
  }
  final String? useIntegral = jsonConvert.convert<String>(json['useIntegral']);
  if (useIntegral != null) {
    integralToCashDiscount.useIntegral = useIntegral;
  }
  return integralToCashDiscount;
}

Map<String, dynamic> $IntegralToCashDiscountToJson(IntegralToCashDiscount entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['available'] = entity.available;
  data['cashValue'] = entity.cashValue;
  data['discountAmount'] = entity.discountAmount;
  data['integralValue'] = entity.integralValue;
  data['maxUseIntegral'] = entity.maxUseIntegral;
  data['memberIntegral'] = entity.memberIntegral;
  data['promotionsCode'] = entity.promotionsCode;
  data['promotionsId'] = entity.promotionsId;
  data['reason'] = entity.reason;
  data['type'] = entity.type;
  data['typeDesc'] = entity.typeDesc;
  data['useIntegral'] = entity.useIntegral;
  return data;
}

extension IntegralToCashDiscountExtension on IntegralToCashDiscount {
  IntegralToCashDiscount copyWith({
    bool? available,
    String? cashValue,
    String? discountAmount,
    String? integralValue,
    String? maxUseIntegral,
    String? memberIntegral,
    String? promotionsCode,
    String? promotionsId,
    String? reason,
    String? type,
    String? typeDesc,
    String? useIntegral,
  }) {
    return IntegralToCashDiscount()
      ..available = available ?? this.available
      ..cashValue = cashValue ?? this.cashValue
      ..discountAmount = discountAmount ?? this.discountAmount
      ..integralValue = integralValue ?? this.integralValue
      ..maxUseIntegral = maxUseIntegral ?? this.maxUseIntegral
      ..memberIntegral = memberIntegral ?? this.memberIntegral
      ..promotionsCode = promotionsCode ?? this.promotionsCode
      ..promotionsId = promotionsId ?? this.promotionsId
      ..reason = reason ?? this.reason
      ..type = type ?? this.type
      ..typeDesc = typeDesc ?? this.typeDesc
      ..useIntegral = useIntegral ?? this.useIntegral;
  }
}